/*
 * @Author: jiu yin
 * @Date: 2024-06-28 12:52:26
 * @LastEditTime: 2024-06-28 13:14:04
 * @LastEditors: jiu yin zhen jing
 * @FilePath: \studio-web-admin\src\utils\eventBus\index.js
 * jiu
 */

class EventBus {
   constructor() {
      this.eventBus = {}
   }

   on(key, callback) {
      if (!this.eventBus[key]) this.eventBus[key] = [];
      this.eventBus[key].push(callback)
   }

   off(key, callback) {
      if (!this.eventBus[key]) return;
      this.eventBus[key] = this.eventBus[key].filter(item => item !== callback)
   }

   emit(key, ...args) {
      if (!this.eventBus[key]) return;
      this.eventBus[key].forEach(callback => callback(...args))
   }

}



export default new EventBus();